/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.bean.OvCountBean;
import java.math.BigDecimal;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class OvCountExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"OvCount.xls\"");
		HSSFFont titltFont = workbook.createFont();
		titltFont.setFontHeightInPoints(16);
		titltFont.setBoldweight(700);
		HSSFFont boldFont = workbook.createFont();
		boldFont.setBoldweight(700);
		HSSFCellStyle titleCellStyle = workbook.createCellStyle();
		titleCellStyle.setFont(titltFont);
		titleCellStyle.setAlignment(2);
		titleCellStyle.setVerticalAlignment(1);
		HSSFCellStyle boldStyle = workbook.createCellStyle();
		boldStyle.setFont(boldFont);
		boldStyle.setBorderBottom(1);
		boldStyle.setBorderTop(1);
		boldStyle.setBorderLeft(1);
		boldStyle.setBorderRight(1);
		boldStyle.setAlignment(2);
		boldStyle.setVerticalAlignment(1);
		HSSFCellStyle norStyle = workbook.createCellStyle();
		norStyle.setBorderBottom(1);
		norStyle.setBorderTop(1);
		norStyle.setBorderLeft(1);
		norStyle.setBorderRight(1);
		HSSFSheet sheet = workbook.createSheet("list");
		String title = "产值统计表";
		String searchTime = (String) model.get("searchTime");
		if (searchTime != null && !searchTime.equals("")) {
			title = title + "（" + searchTime + "）";
		}

		HSSFRow r = sheet.createRow(0);
		HSSFCell c = r.createCell(0);
		byte colNum = 12;

		for (int list = 1; list < colNum; ++list) {
			r.createCell((short) list);
		}

		c.setCellStyle(titleCellStyle);
		c.setCellValue(new HSSFRichTextString(title));
		sheet.addMergedRegion(new Region(0, 0, 0, (short) (colNum - 1)));
		r = sheet.createRow(1);
		c = r.createCell(0);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("部门"));
		c = r.createCell(1);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("姓名"));
		c = r.createCell(2);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("职位"));
		c = r.createCell(3);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("当期产值"));
		c = r.createCell(4);
		c.setCellStyle(boldStyle);
		c = r.createCell(5);
		c.setCellStyle(boldStyle);
		c = r.createCell(6);
		c.setCellStyle(boldStyle);
		c = r.createCell(7);
		c.setCellStyle(boldStyle);
		c = r.createCell(8);
		c.setCellStyle(boldStyle);
		c = r.createCell(9);
		c.setCellStyle(boldStyle);
		c = r.createCell(10);
		c.setCellStyle(boldStyle);
		c = r.createCell(11);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("营销产值"));
		r = sheet.createRow(2);
		c = r.createCell(0);
		c.setCellStyle(boldStyle);
		c = r.createCell(1);
		c.setCellStyle(boldStyle);
		c = r.createCell(2);
		c.setCellStyle(boldStyle);
		c = r.createCell(3);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("接单"));
		c = r.createCell(4);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("跟单"));
		c = r.createCell(5);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("设计"));
		c = r.createCell(6);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("制作"));
		c = r.createCell(7);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("收欠费"));
		c = r.createCell(8);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("安装"));
		c = r.createCell(9);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("其他产值"));
		c = r.createCell(10);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("合计"));
		c = r.createCell(11);
		c.setCellStyle(boldStyle);
		sheet.addMergedRegion(new Region(1, 0, 2, 0));
		sheet.addMergedRegion(new Region(1, 1, 2, 1));
		sheet.addMergedRegion(new Region(1, 2, 2, 2));
		sheet.addMergedRegion(new Region(1, 3, 1, 10));
		sheet.addMergedRegion(new Region(1, 11, 2, 11));
		Object[] arg19 = (Object[]) model.get("list");

		for (int totalArr = 0; totalArr < arg19.length; ++totalArr) {
			Object[] os = ((OvCountBean) arg19[totalArr]).getValues();
			r = sheet.createRow(totalArr + 3);
			c = r.createCell(0);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString((String) os[1]));
			c = r.createCell(1);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString((String) os[2]));
			c = r.createCell(2);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString((String) os[3]));
			BigDecimal v = new BigDecimal(0);
			if (os[4] != null) {
				v = (BigDecimal) os[4];
			}

			c = r.createCell(3);
			c.setCellStyle(norStyle);
			c.setCellValue(v.doubleValue());
			v = new BigDecimal(0);
			if (os[5] != null) {
				v = (BigDecimal) os[5];
			}

			c = r.createCell(4);
			c.setCellStyle(norStyle);
			c.setCellValue(v.doubleValue());
			v = new BigDecimal(0);
			if (os[6] != null) {
				v = (BigDecimal) os[6];
			}

			c = r.createCell(5);
			c.setCellStyle(norStyle);
			c.setCellValue(v.doubleValue());
			v = new BigDecimal(0);
			if (os[7] != null) {
				v = (BigDecimal) os[7];
			}

			c = r.createCell(6);
			c.setCellStyle(norStyle);
			c.setCellValue(v.doubleValue());
			v = new BigDecimal(0);
			if (os[8] != null) {
				v = (BigDecimal) os[8];
			}

			c = r.createCell(7);
			c.setCellStyle(norStyle);
			c.setCellValue(v.doubleValue());
			v = new BigDecimal(0);
			if (os[9] != null) {
				v = (BigDecimal) os[9];
			}

			c = r.createCell(8);
			c.setCellStyle(norStyle);
			c.setCellValue(v.doubleValue());
			v = new BigDecimal(0);
			if (os[10] != null) {
				v = (BigDecimal) os[10];
			}

			c = r.createCell(9);
			c.setCellStyle(norStyle);
			c.setCellValue(v.doubleValue());
			v = new BigDecimal(0);
			if (os[11] != null) {
				v = (BigDecimal) os[11];
			}

			c = r.createCell(10);
			c.setCellStyle(norStyle);
			c.setCellValue(v.doubleValue());
			v = new BigDecimal(0);
			if (os[12] != null) {
				v = (BigDecimal) os[12];
			}

			c = r.createCell(11);
			c.setCellStyle(norStyle);
			c.setCellValue(v.doubleValue());
		}

		BigDecimal[] arg20 = (BigDecimal[]) model.get("totalArr");
		r = sheet.createRow(3 + arg19.length);
		c = r.createCell(0);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("合计"));
		c = r.createCell(1);
		c.setCellStyle(norStyle);
		c = r.createCell(2);
		c.setCellStyle(norStyle);
		c = r.createCell(3);
		c.setCellStyle(norStyle);
		c.setCellValue(arg20[0].doubleValue());
		c = r.createCell(4);
		c.setCellStyle(norStyle);
		c.setCellValue(arg20[1].doubleValue());
		c = r.createCell(5);
		c.setCellStyle(norStyle);
		c.setCellValue(arg20[2].doubleValue());
		c = r.createCell(6);
		c.setCellStyle(norStyle);
		c.setCellValue(arg20[3].doubleValue());
		c = r.createCell(7);
		c.setCellStyle(norStyle);
		c.setCellValue(arg20[4].doubleValue());
		c = r.createCell(8);
		c.setCellStyle(norStyle);
		c.setCellValue(arg20[5].doubleValue());
		c = r.createCell(9);
		c.setCellStyle(norStyle);
		c.setCellValue(arg20[6].doubleValue());
		c = r.createCell(10);
		c.setCellStyle(norStyle);
		c.setCellValue(arg20[7].doubleValue());
		c = r.createCell(11);
		c.setCellStyle(norStyle);
		c.setCellValue(arg20[8].doubleValue());
		sheet.addMergedRegion(new Region(3 + arg19.length, 0, 3 + arg19.length,
				2));
		ServletOutputStream arg21 = response.getOutputStream();
		workbook.write(arg21);
		arg21.flush();
		arg21.close();
	}
}